package com.xkdx.guangguang.fragment.shop.brandofshop;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.BrandDetail;

public class FloorsOfShopModule extends AbsModule {
	List<SingleFloorInfo> list;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getShopFloorBrand_v2")) {
					list = parserFloorInfo(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}

	// 解析楼层
	private List<SingleFloorInfo> parserFloorInfo(JSONObject person)
			throws Exception {
		List<SingleFloorInfo> list = new ArrayList<SingleFloorInfo>();
		try {
			if (person == null) {
				return null;
			}
			JSONObject stut = (JSONObject) person.get("Result");
			JSONArray listInfo = (JSONArray) stut.getJSONArray("FloorListInfo");
			for (int j = 0; j < listInfo.length(); j++) {
				SingleFloorInfo singleFloorInfo = new SingleFloorInfo();
				JSONObject pic = (JSONObject) listInfo.opt(j);
				singleFloorInfo.setFloorName(pic.getString("FloorName"));
				JSONArray brandList = pic.getJSONArray("BrandList");
				List<BrandDetail> Brandlist = new ArrayList<BrandDetail>();
				if (brandList != null) {
					for (int i = 0; i < brandList.length(); i++) {
						BrandDetail brand = new BrandDetail();
						JSONObject obj = (JSONObject) brandList.opt(i);
						brand.setShopName(obj.getString("ShopName"));
						brand.setBrandName(obj.getString("BrandName"));
						brand.setBrandID(Integer.valueOf(obj.getString("ShopID")));
						brand.setBrandNameEn(obj.getString("BrandNameEn"));
						brand.setCard(obj.getString("Card"));
						brand.setBrandSimpleName(obj
								.getString("BrandSimpleName"));
						brand.setLogo(obj.getString("Logo"));
						Brandlist.add(brand);
					}
				}
				singleFloorInfo.setList(Brandlist);
				list.add(singleFloorInfo);
			}

		} catch (Exception e) {
			throw e;
		}
		return list;
	}

	@SuppressWarnings("serial")
	public class SingleFloorInfo implements Serializable {
		String FloorName;
		List<BrandDetail> list;

		public String getFloorName() {
			return FloorName;
		}

		public void setFloorName(String floorName) {
			FloorName = floorName;
		}

		public List<BrandDetail> getList() {
			return list;
		}

		public void setList(List<BrandDetail> list) {
			this.list = list;
		}

	}

}
